﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SystemModule;
using System.Collections;

namespace M2Server
{
    public partial class TPlayObject
    {
        /// <summary>
        /// 增加金币
        /// </summary>
        /// <param name="tGold"></param>
        /// <returns></returns>
        public bool IncGold(int tGold)
        {
            bool result = false;
            if (this.m_nGold + tGold <= M2Share.g_Config.nHumanMaxGold)
            {
                this.m_nGold += tGold;
                result = true;
            }
            return result;
        }

        /// <summary>
        /// 增加游戏金币
        /// </summary>
        /// <param name="nGameGold"></param>
        public void IncGameGold(int nGameGold)
        {
            m_nGameGold += nGameGold;
        }

        /// <summary>
        /// 增加金刚石
        /// </summary>
        /// <param name="nGameDiaMond"></param>
        public void IncGameDiaMond(int nGameDiaMond)
        {
            m_nGAMEDIAMOND += nGameDiaMond;
        }

        /// <summary>
        /// 增加灵符
        /// </summary>
        /// <param name="nGameGird"></param>
        public void IncGameGird(int nGameGird)
        {
            m_nGAMEGIRD += nGameGird;
        }

        /// <summary>
        /// 增加声望
        /// </summary>
        /// <param name="nGamePoint"></param>
        public void IncGamePoint(int nGamePoint)
        {
            m_nGamePoint += (UInt16)nGamePoint;
        }

        /// <summary>
        /// 减游戏币
        /// </summary>
        /// <param name="nGold"></param>
        /// <returns></returns>
        public bool DecGold(int nGold)
        {
            bool result = false;
            if (this.m_nGold >= nGold)
            {
                this.m_nGold -= nGold;
                result = true;
            }
            return result;
        }

        /// <summary>
        /// 减游戏点
        /// </summary>
        /// <param name="nGameGold"></param>
        public void DecGameGold(int nGameGold)
        {
            if (m_nGameGold >= nGameGold)
            {
                m_nGameGold -= nGameGold;
            }
            else
            {
                m_nGameGold = 0;
            }
        }

        /// <summary>
        /// 减游戏点
        /// </summary>
        /// <param name="nGamePoint"></param>
        public void DecGamePoint(int nGamePoint)
        {
            if (m_nGamePoint >= nGamePoint)
            {
                m_nGamePoint -= (UInt16)nGamePoint;
            }
            else
            {
                m_nGamePoint = 0;
            }
        }

        /// <summary>
        /// 玩家包裹是否满了
        /// </summary>
        /// <returns></returns>
        public bool IsEnoughBag()
        {
            return this.m_ItemList.Count < Grobal2.MAXBAGITEM;
        }


        /// <summary>
        /// 召唤强化卷,把招出的宝宝变成7级
        /// </summary>
        /// <returns></returns>
        public bool CallMobeItem()
        {
            bool result = false;
            TBaseObject Slave;
            if (this.m_SlaveList.Count == 0)
            {
                this.SysMsg("您没有召唤宝宝,不能使用此物品!", TMsgColor.c_Red, TMsgType.t_Hint);
                return result;
            }
            if (this.m_SlaveList.Count > 0)
            {
                for (int i = 0; i < this.m_SlaveList.Count; i++)
                {
                    Slave = this.m_SlaveList[i];
                    if (Slave.m_btRaceServer == Grobal2.RC_PLAYMOSTER) // 分身不能调级
                    {
                        continue;
                    }
                    if (Slave.m_btSlaveExpLevel < 7)
                    {
                        Slave.m_btSlaveExpLevel = 7;
                        Slave.RecalcAbilitys();//改变等级,刷新属性
                        Slave.RefNameColor();
                        Slave.SendRefMsg(Grobal2.RM_MYSHOW, Grobal2.ET_OBJECTLEVELUP, 0, 0, 0, "");// 宝宝升级动画 
                        result = true;
                        this.SysMsg("在神秘的力量影响下，您的宠物:" + Slave.m_sCharName + " 成长为7级", TMsgColor.BB_Fuchsia, TMsgType.t_Hint);
                        break;
                    }
                }
            }
            return result;
        }

        /// <summary>
        /// 全部修复,需要的持久值
        /// </summary>
        /// <returns></returns>
        public int RepairAllItemDura()
        {
            int result = 0;
            int nWhere;
            TStdItem StdItem;
            for (nWhere = m_UseItems.GetLowerBound(0); nWhere <= m_UseItems.GetUpperBound(0); nWhere++)
            {
                if (this.m_UseItems[nWhere] != null && this.m_UseItems[nWhere].wIndex > 0)
                {
                    StdItem = M2Share.UserEngine.GetStdItem(this.m_UseItems[nWhere].wIndex);
                    if (StdItem != null)
                    {
                        if (((this.m_UseItems[nWhere].DuraMax / 1000) > (this.m_UseItems[nWhere].Dura / 1000)) && (StdItem.StdMode != 7) && (StdItem.StdMode != 25) && (StdItem.StdMode != 43)
                            && (StdItem.AniCount != 21))
                        {
                            if (this.CheckItemValue(this.m_UseItems[nWhere], 3)) // 禁止修
                            {
                                continue;
                            }
                            else if (this.PlugOfCheckCanItem(3, StdItem.Name, false, 0, 0))// 禁止物品规则(管理插件功能)
                            {
                                continue;
                            }
                            result += (this.m_UseItems[nWhere].DuraMax - this.m_UseItems[nWhere].Dura);
                        }
                    }
                }
            }
            return result;
        }

        /// <summary>
        /// 修复身上全部装备
        /// </summary>
        public void RepairAllItem(int DureCount, bool boDec)
        {
            int nWhere;
            int RepCount;
            TStdItem StdItem;
            for (nWhere = m_UseItems.GetLowerBound(0); nWhere <= m_UseItems.GetUpperBound(0); nWhere++)
            {
                if (this.m_UseItems[nWhere] != null && this.m_UseItems[nWhere].wIndex > 0)
                {
                    StdItem = M2Share.UserEngine.GetStdItem(this.m_UseItems[nWhere].wIndex);
                    if (StdItem != null)
                    {
                        if (((this.m_UseItems[nWhere].DuraMax / 1000) > (this.m_UseItems[nWhere].Dura / 1000)) && (StdItem.StdMode != 7) && (StdItem.StdMode != 25) && (StdItem.StdMode != 43) && (StdItem.AniCount != 21))
                        {
                            if (this.CheckItemValue(this.m_UseItems[nWhere], 3)) // 禁止修
                            {
                                continue;
                            }
                            else if (this.PlugOfCheckCanItem(3, StdItem.Name, false, 0, 0))// 禁止物品规则(管理插件功能)
                            {
                                continue;
                            }
                            if (!boDec)// 修复点够,则直接修复不计算
                            {
                                if ((this.m_UseItems[nWhere].DuraMax / 1000) - (this.m_UseItems[nWhere].Dura / 1000) > 0)
                                {
                                    this.SysMsg(StdItem.Name + "修补成功。", TMsgColor.c_Green, TMsgType.t_Hint);
                                }
                                this.m_UseItems[nWhere].Dura = this.m_UseItems[nWhere].DuraMax;
                                this.SendMsg(this, Grobal2.RM_DURACHANGE, nWhere, this.m_UseItems[nWhere].Dura, this.m_UseItems[nWhere].DuraMax, 0, "");
                            }
                            else
                            {
                                RepCount = (this.m_UseItems[nWhere].DuraMax / 1000) - (this.m_UseItems[nWhere].Dura / 1000);
                                if (DureCount >= RepCount)
                                {
                                    DureCount -= RepCount;
                                    if ((this.m_UseItems[nWhere].DuraMax / 1000) - (this.m_UseItems[nWhere].Dura / 1000) > 0)
                                    {
                                        this.SysMsg(StdItem.Name + "修补成功。", TMsgColor.c_Green, TMsgType.t_Hint);
                                    }
                                    this.m_UseItems[nWhere].Dura = this.m_UseItems[nWhere].DuraMax;
                                    this.SendMsg(this, Grobal2.RM_DURACHANGE, nWhere, this.m_UseItems[nWhere].Dura, this.m_UseItems[nWhere].DuraMax, 0, "");
                                }
                                else if (DureCount > 0)
                                {
                                    this.m_UseItems[nWhere].Dura = Convert.ToUInt16(this.m_UseItems[nWhere].Dura + DureCount * 1000);
                                    this.SendMsg(this, Grobal2.RM_DURACHANGE, nWhere, this.m_UseItems[nWhere].Dura, this.m_UseItems[nWhere].DuraMax, 0, "");
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 随机移动
        /// </summary>
        public void RandomMove()
        {
            if (this.m_PEnvir == null)
            {
                return;
            }
            int nX = HUtil32.Random(this.m_PEnvir.m_nWidth);
            int nY = HUtil32.Random(this.m_PEnvir.m_nHeight);
            this.SendRefMsg(Grobal2.RM_SPACEMOVE_FIRE, 0, 0, 0, 0, "");
            this.SpaceMove(this.m_sMapName, nX, nY, 0);
        }

        /// <summary>
        /// 使用物品
        /// </summary>
        /// <returns></returns>
        private bool EatItems(TStdItem StdItem)
        {
            bool result = false;
            bool bo06;
            int nOldStatus;
            int dwExp;
            if (this.m_PEnvir.m_boNODRUG)
            {
                this.SysMsg(GameMsgDef.sCanotUseDrugOnThisMap, TMsgColor.c_Red, TMsgType.t_Hint);
                return result;
            }
            switch (StdItem.StdMode)
            {
                case 0:
                    switch (StdItem.Shape)
                    {
                        case 1:
                            this.IncHealthSpell(StdItem.AC, StdItem.MAC);
                            result = true;
                            break;
                        case 2:
                            this.m_boUserUnLockDurg = true;
                            result = true;
                            break;
                        case 3:// 增加内功经验物品
                            if (m_boTrainingNG)
                            {
                                dwExp = Convert.ToInt32(StdItem.AC * 1000 + Math.Abs(HUtil32.Round(StdItem.AC * m_NGLevel * 3.92)));// 每级加的内功经验不同
                                GetNGExp(dwExp, 1);
                                result = true;
                            }
                            break;
                        default:
                            if ((StdItem.AC > 0))
                            {
                                this.m_nIncHealth += StdItem.AC;
                            }
                            if ((StdItem.MAC > 0))
                            {
                                this.m_nIncSpell += StdItem.MAC;
                            }
                            result = true;
                            break;
                    }
                    break;
                case 1:
                    nOldStatus = GetMyStatus();
                    m_nHungerStatus += StdItem.DuraMax / 10;
                    m_nHungerStatus = HUtil32._MIN(5000, m_nHungerStatus);
                    if (nOldStatus != GetMyStatus())
                    {
                        RefMyStatus();
                    }
                    result = true;
                    break;
                case 2:
                    result = true;
                    break;
                case 3:
                    if (StdItem.Shape == 12)
                    {
                        bo06 = false;
                        if (HUtil32.LoWord(StdItem.DC) > 0)
                        {
                            this.m_wStatusArrValue[0] = (ushort)HUtil32.LoWord(StdItem.DC);
                            this.m_dwStatusArrTimeOutTick[0] = Convert.ToUInt32(HUtil32.GetTickCount() + HUtil32.HiWord(StdItem.MAC) * 1000);
                            this.SysMsg("攻击力增加" + (HUtil32.HiWord(StdItem.MAC)).ToString() + "秒", TMsgColor.c_Green, TMsgType.t_Hint);
                            bo06 = true;
                        }
                        if (HUtil32.LoWord(StdItem.MC) > 0)
                        {
                            this.m_wStatusArrValue[1] = (ushort)HUtil32.LoWord(StdItem.MC);
                            this.m_dwStatusArrTimeOutTick[1] = Convert.ToUInt32(HUtil32.GetTickCount() + HUtil32.HiWord(StdItem.MAC) * 1000);
                            this.SysMsg("魔法力增加" + (HUtil32.HiWord(StdItem.MAC)).ToString() + "秒", TMsgColor.c_Green, TMsgType.t_Hint);
                            bo06 = true;
                        }
                        if ((byte)(StdItem.SC) > 0)
                        {
                            this.m_wStatusArrValue[2] = (ushort)HUtil32.LoWord(StdItem.SC);
                            this.m_dwStatusArrTimeOutTick[2] = Convert.ToUInt32(HUtil32.GetTickCount() + HUtil32.HiWord(StdItem.MAC) * 1000);
                            this.SysMsg("道术增加" + (HUtil32.HiWord(StdItem.MAC)).ToString() + "秒", TMsgColor.c_Green, TMsgType.t_Hint);
                            bo06 = true;
                        }
                        if (HUtil32.HiWord(StdItem.AC) > 0)
                        {
                            this.m_wStatusArrValue[3] = (ushort)HUtil32.HiWord(StdItem.AC);
                            this.m_dwStatusArrTimeOutTick[3] = Convert.ToUInt32(HUtil32.GetTickCount() + HUtil32.HiWord(StdItem.MAC) * 1000);
                            this.SysMsg("攻击速度增加" + (HUtil32.HiWord(StdItem.MAC)).ToString() + "秒", TMsgColor.c_Green, TMsgType.t_Hint);
                            bo06 = true;
                        }
                        if (HUtil32.LoWord(StdItem.AC) > 0)
                        {
                            this.m_wStatusArrValue[4] = (ushort)HUtil32.LoWord(StdItem.AC);
                            this.m_dwStatusArrTimeOutTick[4] = Convert.ToUInt32(HUtil32.GetTickCount() + HUtil32.HiWord(StdItem.MAC) * 1000);
                            this.SysMsg("生命值增加" + (HUtil32.HiWord(StdItem.MAC)).ToString() + "秒", TMsgColor.c_Green, TMsgType.t_Hint);
                            bo06 = true;
                        }
                        if (HUtil32.LoWord(StdItem.MAC) > 0)
                        {
                            this.m_wStatusArrValue[5] = (ushort)HUtil32.LoWord(StdItem.MAC);
                            this.m_dwStatusArrTimeOutTick[5] = Convert.ToUInt32(HUtil32.GetTickCount() + HUtil32.HiWord(StdItem.MAC) * 1000);
                            this.SysMsg("魔法值增加" + (HUtil32.HiWord(StdItem.MAC)).ToString() + "秒", TMsgColor.c_Green, TMsgType.t_Hint);
                            bo06 = true;
                        }
                        if (bo06)
                        {
                            RecalcAbilitys();
                            this.CompareSuitItem(false);// 套装与身上装备对比
                            this.SendMsg(this, Grobal2.RM_ABILITY, 0, 0, 0, 0, "");
                            result = true;
                        }
                    }
                    else
                    {
                        result = EatUseItems(StdItem.Shape);
                    }
                    break;
            }
            return result;
        }

        /// <summary>
        /// 学习技能书
        /// </summary>
        /// <returns></returns>
        private bool ReadBook(TStdItem StdItem)
        {
            bool result = false;
            TMagic Magic;
            TUserMagic UserMagic = null;
            byte btOldKey;
            if (!(new ArrayList(new int[] { 13, 26, 45, 88, 89, 91 }).Contains(StdItem.NeedLevel)))
            {
                Magic = M2Share.UserEngine.FindMagic(StdItem.Name);
                if (Magic != null)
                {
                    if (!this.IsTrainingSkill(Magic.wMagicId))  // 护体神盾不限制职业
                    {
                        if (((Magic.sDescr == "") || (Magic.sDescr == "内功") ||
                            (Magic.sDescr == "连击")) && ((Magic.btJob == 99) || (Magic.btJob == this.m_btJob) || (Magic.wMagicId == 75)))
                        {
                            if ((Magic.sDescr == "内功") || (Magic.sDescr == "连击"))// 内功技能
                            {
                                if (m_boTrainingNG)// 学过内功心法才能学习技能
                                {
                                    if (m_NGLevel >= Magic.TrainLevel[0])// 等级达到最低要求
                                    {
                                        UserMagic = new TUserMagic();
                                        UserMagic.MagicInfo = Magic;
                                        UserMagic.wMagIdx = Magic.wMagicId;
                                        UserMagic.btKey = 0;
                                        UserMagic.btLevel = 0;
                                        UserMagic.nTranPoint = 0;
                                        this.m_MagicList.Add(UserMagic);
                                        AddSkillFunc(Magic.wMagicId);// 人物学技能触发
                                        RecalcAbilitys();
                                        this.CompareSuitItem(false);// 套装与身上装备对比
                                        SendAddMagic(UserMagic);
                                        result = true;
                                        if ((Magic.sDescr == "连击"))
                                        {
                                            this.m_boCanUseBatter = true;
                                        }
                                    }
                                    else
                                    {
                                        this.SysMsg(string.Format("您的内功心法等级没有达到 {0},不能学习此内功技能！！！", Magic.TrainLevel[0]), TMsgColor.c_Red, TMsgType.t_Hint);
                                    }
                                }
                                else
                                {
                                    this.SysMsg("您没学过内功心法,不能学习此内功技能！！！", TMsgColor.c_Red, TMsgType.t_Hint);
                                }
                            }
                            else
                            {
                                if (this.m_Abil.Level >= Magic.TrainLevel[0]) // 普通技能
                                {
                                    if ((Magic.wMagicId == 68) && ((m_MaxExp68 != 0) || (m_Exp68 != 0)))// 是酒气护体
                                    {
                                        m_MaxExp68 = 0;
                                        m_Exp68 = 0;
                                    }
                                    UserMagic = new TUserMagic();
                                    UserMagic.MagicInfo = Magic;
                                    UserMagic.wMagIdx = Magic.wMagicId;
                                    UserMagic.btKey = 0;
                                    UserMagic.btLevel = 0;
                                    UserMagic.nTranPoint = 0;
                                    this.m_MagicList.Add(UserMagic);
                                    AddSkillFunc(Magic.wMagicId);// 人物学技能触发
                                    RecalcAbilitys();
                                    this.CompareSuitItem(false);// 套装与身上装备对比
                                    if ((this.m_MagicArr[0][MagicConst.SKILL_BANWOL] != null) && (Magic.wMagicId == 25)) // 开启半月
                                    {
                                        if (!this.m_boUseHalfMoon)
                                        {
                                            this.HalfMoonOnOff(true);
                                            unsafe { SendSocket(null, "+WID"); }
                                        }
                                    }
                                    if ((this.m_MagicArr[0][MagicConst.SKILL_ERGUM] != null) && (Magic.wMagicId == 12))// 开启刺杀
                                    {
                                        if (!this.m_boUseThrusting)
                                        {
                                            this.ThrustingOnOff(true);
                                            unsafe { SendSocket(null, "+LNG"); }
                                        }
                                    }
                                    if ((this.m_MagicArr[0][MagicConst.SKILL_89] != null) && (Magic.wMagicId == 89))// 开启四级刺杀
                                    {
                                        if (!this.m_boUseThrusting)
                                        {
                                            this.ThrustingOnOff(true);
                                            unsafe { SendSocket(null, "+4LNG"); }
                                        }
                                    }
                                    SendAddMagic(UserMagic);
                                    result = true;
                                }
                            }
                        }
                        else
                        {
                            this.SysMsg("您的职业不能学习此技能！！！", TMsgColor.c_Red, TMsgType.t_Hint);
                        }
                    }
                    else
                    {
                        this.SysMsg("已经学过此技能,不能再学习！！！", TMsgColor.c_Red, TMsgType.t_Hint);
                    }
                }
            }
            else
            {
                Magic = M2Share.UserEngine.FindMagic(StdItem.NeedLevel);
                if (this.m_Abil.Level >= Magic.TrainLevel[0])
                {
                    if ((Magic != null) && (StdItem.AC == 0))
                    {
                        for (int i = this.m_MagicList.Count - 1; i >= 0; i--)
                        {
                            if (this.m_MagicList.Count <= 0)
                            {
                                break;
                            }
                            UserMagic = this.m_MagicList[i];
                            if (UserMagic != null)
                            {
                                if (((new ArrayList(new int[] { 26, 45, 13 }).Contains(UserMagic.wMagIdx)) && (UserMagic.btLevel < 4)) || (UserMagic.wMagIdx != StdItem.NeedLevel))
                                {
                                    if (UserMagic.MagicInfo.wMagicId == StdItem.Need)
                                    {
                                        this.SendDelMagic(UserMagic);
                                        btOldKey = UserMagic.btKey;// 保存快捷键
                                        UserMagic = null;
                                        this.m_MagicList.RemoveAt(i);
                                        UserMagic.MagicInfo = Magic;
                                        UserMagic.wMagIdx = Magic.wMagicId;
                                        UserMagic.btKey = btOldKey;
                                        UserMagic.btLevel = 4;
                                        UserMagic.nTranPoint = 0;
                                        this.m_MagicList.Add(UserMagic);
                                        this.SendAddMagic(UserMagic);
                                        //((this) as TPlayObject).SendAddMagic(UserMagic);
                                        AddSkillFunc(Magic.wMagicId);// 人物学技能触发 
                                        RecalcAbilitys();
                                        this.CompareSuitItem(false);// 套装与身上装备对比
                                        if ((this.m_MagicArr[0][MagicConst.SKILL_89] != null) && (Magic.wMagicId == 89)) // 开启四级刺杀
                                        {
                                            if (!this.m_boUseThrusting)
                                            {
                                                this.ThrustingOnOff(true);
                                                unsafe { SendSocket(null, "+4LNG"); }
                                            }
                                        }
                                        result = true;
                                        break;
                                    }
                                }
                                else
                                {
                                    this.SysMsg("已经学过此技能,不能再学习！！！", TMsgColor.c_Red, TMsgType.t_Hint);
                                }
                            }
                        }
                    }
                    else
                    {
                        this.SysMsg("您不能学习英雄的技能！！！", TMsgColor.c_Red, TMsgType.t_Hint);
                    }
                }
                else
                {
                    this.SysMsg("您不能学习此技能！！！", TMsgColor.c_Red, TMsgType.t_Hint);
                }
            }
            return result;
        }

        /// <summary>
        /// 使用物品
        /// </summary>
        /// <returns></returns>
        private bool EatUseItems(int nShape)
        {
            bool result = false;
            switch (nShape)
            {
                case 1:
                    this.SendRefMsg(Grobal2.RM_SPACEMOVE_FIRE, 0, 0, 0, 0, "");
                    BaseObjectMove(this.m_sHomeMap, "", "");
                    result = true;
                    break;
                case 2:// 随机传送卷
                    if (!this.m_PEnvir.m_boNORANDOMMOVE)
                    {
                        this.SendRefMsg(Grobal2.RM_SPACEMOVE_FIRE, 0, 0, 0, 0, "");
                        BaseObjectMove(this.m_sMapName, "", "");
                        result = true;
                    }
                    break;
                case 3://回城卷
                    this.SendRefMsg(Grobal2.RM_SPACEMOVE_FIRE, 0, 0, 0, 0, "");
                    if (this.PKLevel() < 2) //PK值小于200则飞回安全区，否则飞回红名村
                    {
                        BaseObjectMove(this.m_sHomeMap, this.m_nHomeX.ToString(), this.m_nHomeY.ToString());
                    }
                    else
                    {
                        BaseObjectMove(M2Share.g_Config.sRedHomeMap, M2Share.g_Config.nRedHomeX.ToString(), M2Share.g_Config.nRedHomeY.ToString());
                    }
                    result = true;
                    break;
                case 4://祝福语
                    if (WeaptonMakeLuck())
                    {
                        result = true;
                    }
                    break;
                case 5://行会回城卷
                    if (this.m_MyGuild != null)
                    {
                        if (!this.m_boInFreePKArea)
                        {
                            TUserCastle Castle = M2Share.g_CastleManager.IsCastleMember(this);
                            if ((Castle != null) && Castle.IsMasterGuild(this.m_MyGuild))
                            {
                                BaseObjectMove(Castle.m_sHomeMap, Castle.GetHomeX().ToString(), Castle.GetHomeY().ToString());
                            }
                            else
                            {
                                this.SysMsg("无效", TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                            result = true;
                        }
                        else
                        {
                            this.SysMsg("此处无法使用", TMsgColor.c_Red, TMsgType.t_Hint);
                        }
                    }
                    break;
                case 9://修复神水
                    if (RepairWeapon())
                    {
                        result = true;
                    }
                    break;
                case 10://超级祝福油
                    if (SuperRepairWeapon())
                    {
                        result = true;
                    }
                    break;
                case 11://彩票
                    if (WinLottery())
                    {
                        result = true;
                    }
                    break;
            }
            return result;
        }

        /// <summary>
        /// 移动到回城点
        /// </summary>
        public void MoveToHome()
        {
            this.SendRefMsg(Grobal2.RM_SPACEMOVE_FIRE, 0, 0, 0, 0, "");
            BaseObjectMove(this.m_sHomeMap, this.m_nHomeX.ToString(), this.m_nHomeY.ToString());
        }

        private void BaseObjectMove(string sMAP, string sX, string sY)
        {
            int nX;
            int nY;
            Envirnoment Envir = this.m_PEnvir;
            if (sMAP == "")
            {
                sMAP = this.m_sMapName;
            }
            if ((sX != "") && (sY != ""))
            {
                nX = HUtil32.Str_ToInt(sX, 0);
                nY = HUtil32.Str_ToInt(sY, 0);
                this.SpaceMove(sMAP, nX, nY, 0);
            }
            else
            {
                this.MapRandomMove(sMAP, 0);
            }
            if ((Envir != this.m_PEnvir) && (this.m_btRaceServer == Grobal2.RC_PLAYOBJECT))
            {
                m_boTimeRecall = false;
            }
        }

        /// <summary>
        /// 使用祝福油,武器加幸运
        /// </summary>
        /// <returns></returns>
        private bool WeaptonMakeLuck()
        {
            bool result = false;
            TStdItem StdItem;
            int nRand;
            bool boMakeLuck;
            byte nCode = 0;
            try
            {
                if (this.m_UseItems[Grobal2.U_WEAPON] == null || this.m_UseItems[Grobal2.U_WEAPON].wIndex <= 0)
                {
                    return result;
                }
                nCode = 1;
                nRand = 0;
                StdItem = M2Share.UserEngine.GetStdItem(this.m_UseItems[Grobal2.U_WEAPON].wIndex);
                nCode = 2;
                if (StdItem != null)
                {
                    nRand = Math.Abs((HUtil32.HiWord(StdItem.DC) - HUtil32.LoWord(StdItem.DC))) / 5;
                }
                nCode = 3;
                if (HUtil32.Random(M2Share.g_Config.nWeaponMakeUnLuckRate) == 1)// 20
                {
                    nCode = 4;
                    this.MakeWeaponUnlock();// 武器加诅咒
                }
                else
                {
                    nCode = 5;
                    boMakeLuck = false;
                    if (this.m_UseItems[Grobal2.U_WEAPON].btValue[4] > 0)
                    {
                        nCode = 6;
                        this.m_UseItems[Grobal2.U_WEAPON].btValue[4] -= 1;
                        this.SysMsg(GameMsgDef.g_sWeaptonMakeLuck, TMsgColor.c_Green, TMsgType.t_Hint);// '武器被加幸运了...'
                        boMakeLuck = true;
                    }
                    else if (this.m_UseItems[Grobal2.U_WEAPON].btValue[3] < M2Share.g_Config.nWeaponMakeLuckPoint1)
                    {
                        nCode = 7;
                        this.m_UseItems[Grobal2.U_WEAPON].btValue[3]++;
                        this.SysMsg(GameMsgDef.g_sWeaptonMakeLuck, TMsgColor.c_Green, TMsgType.t_Hint);// '武器被加幸运了...'
                        boMakeLuck = true;
                    }
                    else if ((this.m_UseItems[Grobal2.U_WEAPON].btValue[3] < M2Share.g_Config.nWeaponMakeLuckPoint2) && (HUtil32.Random(nRand + M2Share.g_Config.nWeaponMakeLuckPoint2Rate) == 1))
                    {
                        nCode = 8;
                        this.m_UseItems[Grobal2.U_WEAPON].btValue[3]++;
                        this.SysMsg(GameMsgDef.g_sWeaptonMakeLuck, TMsgColor.c_Green, TMsgType.t_Hint);// '武器被加幸运了...'
                        boMakeLuck = true;
                    }
                    else if ((this.m_UseItems[Grobal2.U_WEAPON].btValue[3] < M2Share.g_Config.nWeaponMakeLuckPoint3) && (HUtil32.Random(nRand * M2Share.g_Config.nWeaponMakeLuckPoint3Rate) == 1))
                    {
                        nCode = 9;
                        this.m_UseItems[Grobal2.U_WEAPON].btValue[3]++;
                        this.SysMsg(GameMsgDef.g_sWeaptonMakeLuck, TMsgColor.c_Green, TMsgType.t_Hint);// '武器被加幸运了...'
                        boMakeLuck = true;
                    }
                    nCode = 10;
                    if (this.m_btRaceServer == Grobal2.RC_PLAYOBJECT)
                    {
                        nCode = 11;
                        RecalcAbilitys();
                        nCode = 12;
                        this.CompareSuitItem(false);// 套装与身上装备对比
                        nCode = 13;
                        this.SendMsg(this, Grobal2.RM_ABILITY, 0, 0, 0, 0, "");
                        this.SendMsg(this, Grobal2.RM_SUBABILITY, 0, 0, 0, 0, "");
                    }
                    nCode = 14;
                    if (!boMakeLuck)
                    {
                        // '无效'
                        this.SysMsg(GameMsgDef.g_sWeaptonNotMakeLuck, TMsgColor.c_Green, TMsgType.t_Hint);
                    }
                }
            }
            catch
            {
                M2Share.MainOutMessage("[异常] TPlayObject.WeaptonMakeLuck Code:" + nCode);
            }
            result = true;
            return result;
        }

        /// <summary>
        /// 修复武器
        /// </summary>
        /// <returns></returns>
        private bool RepairWeapon()
        {
            TUserItem UserItem = this.m_UseItems[Grobal2.U_WEAPON];
            if (UserItem == null) { return false; }
            if ((UserItem.wIndex <= 0) || ((UserItem.DuraMax / 1000) <= (UserItem.Dura / 1000)))
            {
                return false;
            }
            if (this.CheckItemValue(UserItem, 3))// 禁止修
            {
                return false;
            }
            UserItem.DuraMax -= Convert.ToUInt16((UserItem.DuraMax - UserItem.Dura) / M2Share.g_Config.nRepairItemDecDura); // 30
            int nDura = HUtil32._MIN(5000, UserItem.DuraMax - UserItem.Dura);
            if (nDura > 0)
            {
                UserItem.Dura += (ushort)nDura;
                this.SendMsg(this, Grobal2.RM_DURACHANGE, 1, UserItem.Dura, UserItem.DuraMax, 0, "");// '武器修复成功...'
                this.SysMsg(GameMsgDef.g_sWeaponRepairSuccess, TMsgColor.c_Green, TMsgType.t_Hint);
                return true;
            }
            return false;
        }

        /// <summary>
        /// 超级修理武器
        /// </summary>
        /// <returns></returns>
        private bool SuperRepairWeapon()
        {
            bool result = false;
            if (this.m_UseItems[Grobal2.U_WEAPON] == null || this.m_UseItems[Grobal2.U_WEAPON].wIndex <= 0)
            {
                return result;
            }
            if (this.CheckItemValue(this.m_UseItems[Grobal2.U_WEAPON], 3)) //禁止修
            {
                return result;
            }
            this.m_UseItems[Grobal2.U_WEAPON].Dura = this.m_UseItems[Grobal2.U_WEAPON].DuraMax;
            this.SendMsg(this, Grobal2.RM_DURACHANGE, 1, this.m_UseItems[Grobal2.U_WEAPON].Dura, this.m_UseItems[Grobal2.U_WEAPON].DuraMax, 0, "");// '武器修复成功...'
            this.SysMsg(GameMsgDef.g_sWeaponRepairSuccess, TMsgColor.c_Green, TMsgType.t_Hint);
            return true;
        }

        /// <summary>
        /// 赢彩票
        /// </summary>
        /// <returns></returns>
        private bool WinLottery()
        {
            bool result;
            int nGold;
            int nWinLevel;
            int nRate;
            nGold = 0;
            nWinLevel = 0;
            nRate = HUtil32.Random(M2Share.g_Config.nWinLotteryRate);
            if ((nRate >= M2Share.g_Config.nWinLottery6Min) && (nRate <= M2Share.g_Config.nWinLottery6Max))
            {
                if (M2Share.g_Config.nWinLotteryCount < M2Share.g_Config.nNoWinLotteryCount)
                {
                    nGold = M2Share.g_Config.nWinLottery6Gold;
                    nWinLevel = 6;
                    M2Share.g_Config.nWinLotteryLevel6++;
                    M2Share.g_Config.nWinLotteryCount++;// 中奖人数
                    M2Share.g_Config.nNoWinLotteryCount -= 1;// 未中奖人数
                }
            }
            else if ((nRate >= M2Share.g_Config.nWinLottery5Min) && (nRate <= M2Share.g_Config.nWinLottery5Max))
            {
                if (M2Share.g_Config.nWinLotteryCount < M2Share.g_Config.nNoWinLotteryCount)
                {
                    nGold = M2Share.g_Config.nWinLottery5Gold;
                    nWinLevel = 5;
                    M2Share.g_Config.nWinLotteryLevel5++;
                    M2Share.g_Config.nWinLotteryCount++;// 中奖人数
                    M2Share.g_Config.nNoWinLotteryCount -= 1;// 未中奖人数
                }
            }
            else if ((nRate >= M2Share.g_Config.nWinLottery4Min) && (nRate <= M2Share.g_Config.nWinLottery4Max))
            {
                if (M2Share.g_Config.nWinLotteryCount < M2Share.g_Config.nNoWinLotteryCount)
                {
                    nGold = M2Share.g_Config.nWinLottery4Gold;
                    nWinLevel = 4;
                    M2Share.g_Config.nWinLotteryLevel4++;
                    M2Share.g_Config.nWinLotteryCount++;// 中奖人数
                    M2Share.g_Config.nNoWinLotteryCount -= 1;// 未中奖人数
                }
            }
            else if ((nRate >= M2Share.g_Config.nWinLottery3Min) && (nRate <= M2Share.g_Config.nWinLottery3Max))
            {
                if (M2Share.g_Config.nWinLotteryCount < M2Share.g_Config.nNoWinLotteryCount)
                {
                    nGold = M2Share.g_Config.nWinLottery3Gold;
                    nWinLevel = 3;
                    M2Share.g_Config.nWinLotteryLevel3++;
                    M2Share.g_Config.nWinLotteryCount++;// 中奖人数
                    M2Share.g_Config.nNoWinLotteryCount -= 1;// 未中奖人数
                }
            }
            else if ((nRate >= M2Share.g_Config.nWinLottery2Min) && (nRate <= M2Share.g_Config.nWinLottery2Max))
            {
                if (M2Share.g_Config.nWinLotteryCount < M2Share.g_Config.nNoWinLotteryCount)
                {
                    nGold = M2Share.g_Config.nWinLottery2Gold;
                    nWinLevel = 2;
                    M2Share.g_Config.nWinLotteryLevel2++;
                    M2Share.g_Config.nWinLotteryCount++;// 中奖人数
                    M2Share.g_Config.nNoWinLotteryCount -= 1;// 未中奖人数
                }
            }
            else if ((nRate >= M2Share.g_Config.nWinLottery1Min) && (nRate <= M2Share.g_Config.nWinLottery1Max))
            {
                if (M2Share.g_Config.nWinLotteryCount < M2Share.g_Config.nNoWinLotteryCount)
                {
                    nGold = M2Share.g_Config.nWinLottery1Gold;
                    nWinLevel = 1;
                    M2Share.g_Config.nWinLotteryLevel1++;
                    M2Share.g_Config.nWinLotteryCount++;// 中奖人数
                    M2Share.g_Config.nNoWinLotteryCount -= 1;// 未中奖人数
                }
            }
            if (nGold > 0)
            {
                switch (nWinLevel)
                {
                    case 1:// '祝贺您，中了一等奖。'
                        this.SysMsg(GameMsgDef.g_sWinLottery1Msg, TMsgColor.c_Green, TMsgType.t_Hint);
                        break;
                    case 2:// '祝贺您，中了二等奖。'
                        this.SysMsg(GameMsgDef.g_sWinLottery2Msg, TMsgColor.c_Green, TMsgType.t_Hint);
                        break;
                    case 3:// '祝贺您，中了三等奖。'
                        this.SysMsg(GameMsgDef.g_sWinLottery3Msg, TMsgColor.c_Green, TMsgType.t_Hint);
                        break;
                    case 4:// '祝贺您，中了四等奖。'
                        this.SysMsg(GameMsgDef.g_sWinLottery4Msg, TMsgColor.c_Green, TMsgType.t_Hint);
                        break;
                    case 5:// '祝贺您，中了五等奖。'
                        this.SysMsg(GameMsgDef.g_sWinLottery5Msg, TMsgColor.c_Green, TMsgType.t_Hint);
                        break;
                    case 6:// '祝贺您，中了六等奖。'
                        this.SysMsg(GameMsgDef.g_sWinLottery6Msg, TMsgColor.c_Green, TMsgType.t_Hint);
                        break;
                }
                if (IncGold(nGold))
                {
                    this.GoldChanged();
                }
                else
                {
                    this.DropGoldDown(nGold, true, null, null);
                }
            }
            else
            {
                M2Share.g_Config.nNoWinLotteryCount += 500;// '等下次机会吧！！！'
                this.SysMsg(GameMsgDef.g_sNotWinLotteryMsg, TMsgColor.c_Red, TMsgType.t_Hint);
            }
            result = true;
            return result;
        }

        /// <summary>
        /// 人物死亡触发
        /// </summary>
        /// <returns></returns>
        public bool DieFunc()
        {
            bool result = false;
            if (M2Share.g_FunctionNPC != null)
            {
                M2Share.g_FunctionNPC.GotoLable(this, "@PlayDie", false);
                result = true;
            }
            return result;
        }

        /// <summary>
        /// 人物学技能触发
        /// </summary>
        /// <returns></returns>
        public bool AddSkillFunc(int MagicID)
        {
            if (M2Share.g_FunctionNPC != null)
            {
                M2Share.g_FunctionNPC.GotoLable(this, "@HeroplaySkill" + MagicID, false);
                return true;
            }
            return false;
        }

        /// <summary>
        /// 英雄学技能触发
        /// </summary>
        /// <returns></returns>
        public bool HeroAddSkillFunc(int MagicID)
        {
            if (M2Share.g_FunctionNPC != null)
            {
                M2Share.g_FunctionNPC.GotoLable(this, "@playSkill" + MagicID, false);
                return true;
            }
            return false;
        }

        /// <summary>
        /// 宝宝杀死怪触发
        /// </summary>
        /// <returns></returns>
        public bool KillMissionMob()
        {
            if (M2Share.g_FunctionNPC != null)
            {
                M2Share.g_FunctionNPC.GotoLable(this, "@KillMissionMob", false);
                return true;
            }
            return false;
        }

        /// <summary>
        /// 人物升级触发
        /// </summary>
        /// <returns></returns>
        public bool LevelUpFunc()
        {
            if (M2Share.g_FunctionNPC != null)
            {
                M2Share.g_FunctionNPC.GotoLable(this, "@PlayLevelUp", false);
                return true;
            }
            return false;
        }

        /// <summary>
        /// 人物内功升级触发
        /// </summary>
        /// <returns></returns>
        public bool NGLevelUpFunc()
        {
            if (M2Share.g_FunctionNPC != null)
            {
                M2Share.g_FunctionNPC.GotoLable(this, "@PlayNGLevelUp", false);
                return true;
            }
            return false;
        }

        /// <summary>
        /// 杀人触发
        /// </summary>
        /// <returns></returns>
        public bool KillPlayFunc()
        {
            bool result = false;
            try
            {
                if (M2Share.g_FunctionNPC != null)
                {
                    // 地图杀人触发
                    if (this.m_PEnvir != null)
                    {
                        if (this.m_PEnvir.m_boKILLFUNC)
                        {
                            M2Share.g_FunctionNPC.GotoLable(this, "@KillPlay" + this.m_PEnvir.m_nKILLFUNC, false);
                        }
                    }
                    M2Share.g_FunctionNPC.GotoLable(this, "@KillPlay", false);
                    result = true;
                }
            }
            catch
            {
                M2Share.MainOutMessage("[异常] TPlayObject.KillPlayFunc");
            }
            return result;
        }

        /// <summary>
        /// 地图杀怪触发
        /// </summary>
        /// <returns></returns>
        public bool KillMonsterFunc_GotoKillMonsterFunc()
        {
            bool result = false;
            if (M2Share.g_FunctionNPC != null)
            {
                if (this.m_PEnvir != null)
                {
                    if (this.m_PEnvir.m_boKILLFUNC)
                    {
                        M2Share.g_FunctionNPC.GotoLable(this, "@KillMonster" + this.m_PEnvir.m_nKILLFUNC, false);
                    }
                }
                M2Share.g_FunctionNPC.GotoLable(this, "@KillMonster", false);
                result = true;
            }
            return result;
        }

        /// <summary>
        /// 执行杀怪触发
        /// </summary>
        /// <param name="BaseObject"></param>
        /// <returns></returns>
        public bool KillMonsterFunc(TBaseObject BaseObject)
        {
            bool result = false;
            try
            {
                if (BaseObject != null)
                {
                    if (!BaseObject.m_boGhost)
                    {
                        if (BaseObject.m_btRaceServer >= Grobal2.RC_ANIMAL)
                        {
                            m_sString[0] = BaseObject.m_sCharName;
                            m_nInteger[0] = BaseObject.m_Abil.Level;
                            result = KillMonsterFunc_GotoKillMonsterFunc();
                        }
                    }
                }
            }
            catch
            {
                M2Share.MainOutMessage("[异常] TPlayObject.KillMonsterFunc");
            }
            return result;
        }
    }
}